import apple.laf.JRSUIUtils;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Created by zhangjinrui on 17/6/27.
 */

class TreeLinkNode {
    int val;
    TreeLinkNode left, right, next;

    TreeLinkNode(int x) {
        val = x;
    }
}

public class Solution116 {

    public static void main(String args[]) {
        Solution116 s = new Solution116();
    }

    public void connect(TreeLinkNode root) {
       TreeLinkNode levelStart = root;
       while(levelStart != null){
           TreeLinkNode p = levelStart;
           while(p != null && p.left != null){
               p.left.next = p.right;
               if(p.right != null && p.next != null){
                    p.right.next = p.next.left;
               }
               p = p.next;
           }
           levelStart = levelStart.left;
       }
    }
}
